/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bef.dtgenerator.api;

import com.inspur.edp.bef.bizentity.GspBizEntityObject;
import com.inspur.edp.bef.dtgenerator.api.entityInterface.BEEntityInterfaceGenerator;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.das.commonmodel.IGspCommonModel;
import com.inspur.edp.das.commonmodel.IGspCommonObject;

public final class ApiHelper {
  public static String getBEAllInterfaceClassName(IGspCommonObject cmObj) {
    final String nameTemplate = "I%1$sEntity";
    return String.format(nameTemplate, cmObj.getCode());
  }

  public static String getBEMgrInterfaceClassName(IGspCommonModel model) {
    final String itemNameTemplate = "I%1$sBEManager";
    return String.format(itemNameTemplate, model.getCode());
  }

  public static String getBEMgrAllInterfaceClassName(IGspCommonModel model) {
    final String itemNameTemplate = "I%1$sService";
    return String.format(itemNameTemplate, model.getCode());
  }

//  public static MediateType getBEAssFactoryInterfaceClassName(IGspCommonObject obj) {
//    String nameSpace = obj.getBelongModel().getApiNamespace().getDefaultNamespace();
//    String className = BEAssFactoryInterfaceGenerator.getItemName(obj);
//    return new MediateType(nameSpace, className);
//  }

//  public static MediateType getMgrAssFactoryInterfaceClassName(IGspCommonModel model) {
//    String nameSpace = getCmNamespace(model);
//    String className = MgrAssFactoryInterfaceGenerator.getItemName(model);
//    return new MediateType(nameSpace, className);
//  }

  public static MediateType getBEEntityInterfaceClassName(IGspCommonObject obj) {
    String nameSpace = getCmNamespace(obj.getBelongModel());
    String className = BEEntityInterfaceGenerator.getName((GspBizEntityObject) obj);
    return new MediateType(nameSpace, className);
  }

  public static MediateType getBeEntityAllInterfaceClassName(IGspCommonObject obj) {
    String nameSpace = getCmNamespace(obj.getBelongModel());
    String className =
        getBEAllInterfaceClassName(
            (obj instanceof GspBizEntityObject) ? obj : null);
    return new MediateType(nameSpace, className);
  }

  private static String getCmNamespace(IGspCommonModel model) {
    return model.getApiNamespace().getDefaultNamespace();
  }
}
